package com.iecas.utils;

import lombok.Data;

@Data
public class ProgressBar {
    private String head = "[";
    private String tail = "]";
    private String content = "#";
    private Integer progress = 0;
    private String desc = "";

    public ProgressBar() {

    }

    public String updateProgress(Integer progress) {
        if (progress < 0) progress = 0;
        if (progress > 100) progress = 100;
        this.progress = progress;
        return print(true);
    }

    public String print(boolean p) {
        int count = progress / 2;
        StringBuilder sb = new StringBuilder();
        sb.append("\r");
        sb.append(head);
        for (int j = 0; j < 50; j++) {
            if (count >= j) {
                sb.append(content);
            } else {
                sb.append(" ");
            }
        }
        sb.append(tail);
        sb.append(" " + progress + "%");
        sb.append(" ");
        sb.append(desc);
//        if (p) System.out.print(sb);
        return sb.toString();
    }
}
